use "${datadir}\HTB_main_cleaned_counterfactual_sub", replace

gen eq_diff = hpv_diff_round - lb_diff_round
gen eq_credcard_diff = hpv_diff_round - lb_diff_round
replace fvmp_mortgage_diff_round = - fvmp_mortgage_diff_round 
replace fvmp_credcard_diff_round = - fvmp_credcard_diff_round 


*--- By LTV band
// mortgage rate
forvalues i = 1/3 {
	local x full_mortgage_diff_round  
		
		// Variables in pounds
		preserve
			keep if band_large == `i'
			collapse `x'_mea=`x' (sd) `x'_sd=`x' ///
				(p10) `x'_p10=`x' (p50) `x'_p50=`x' (p90) `x'_p90=`x'
			format _all %5.1f
			quietly: latexTable
			outsheet using "${tabledir}\`x'_`i'.tex", ///
				replace noquote nonames
		restore
		
		// Relative to income
		capture gen `x'_inc = `x' / (gross_income/12)
		preserve
			keep if band_large == `i'
			collapse `x'_mea=`x'_inc (sd) `x'_sd=`x'_inc ///
				(p10) `x'_p10=`x'_inc (p50) `x'_p50=`x'_inc (p90) `x'_p90=`x'_inc
			format _all %5.1f
			quietly: latexTable
			outsheet using "${tabledir}\`x'_inc_`i'.tex", ///
				replace noquote nonames
		restore

}

// credcard rate
forvalues i = 1/3 {
	local x in full_credcard_diff_round 
		
		// Variables in pounds
		preserve
			keep if band_large == `i'
			collapse `x'_mea=`x' (sd) `x'_sd=`x' 
			format _all %5.1f
			quietly: latexTable
			outsheet using "${tabledir}\`x'_`i'.tex", ///
				replace noquote nonames
		restore
		
		// Relative to income
		capture gen `x'_inc = `x' / (gross_income/12)
		preserve
			keep if band_large == `i'
			collapse `x'_mea=`x'_inc (sd) `x'_sd=`x'_inc 
			format _all %5.1f
			quietly: latexTable
			outsheet using "${tabledir}\`x'_inc_`i'.tex", ///
				replace noquote nonames
		restore
	
}
